#include "MakeHaffman.h"

MakeHaffman::MakeHaffman()
{}

void haffman::make_haffman()
{
  tree *tem[bas_len];
  memcpy(tem, bas, sizeof(tree *) * bas_len);
  if (haff_root) delete haff_root;
  int num = 0;
  while (num < bas_len - 1)
  {
    new_sort(tem, num, bas_len - 1);
    haff_root             = new tree;
    haff_root->times      = tem[num]->times + tem[num + 1]->times;
    haff_root->left_tree  = tem[num];
    haff_root->right_tree = tem[num + 1];
    tem[num + 1]          = haff_root;
    ++num;
  }
  haff_root->MakeCodeTable(0, 0); // haffman 序列形成
}
